﻿using UnityEngine;
using System.Collections;
using System;

public class RateApp
{
	private static long OriginTime {
		set { PlayerPrefs.SetString ("OriginTime", value.ToString ()); }
		get { return long.Parse (PlayerPrefs.GetString ("OriginTime", "0")); }
	}

	private static bool HasRate {
		set{ PlayerPrefs.SetInt ("HasRate", Convert.ToInt32 (value)); }
		get{ return Convert.ToBoolean (PlayerPrefs.GetInt ("HasRate", 0)); }
	}

	private static int day = 2;

	public static void GoRateApp ()
	{
		OriginTime = System.DateTime.Now.Ticks;

		TimeSpan timeSpan = new TimeSpan (System.DateTime.Now.Ticks - OriginTime);
		if (timeSpan.TotalDays > day && !HasRate) {
			OriginTime = System.DateTime.Now.Ticks;

			#if UNITY_ANDROID
			var rateApp = new AndroidJavaClass ("com.tj.RateApp");
			rateApp.CallStatic ("ShowNote");
			#endif

			#if UNITY_IPHONE
            IOSFunction.RateApp(ChannelData.AppStoreId,
                (bool bo) =>
                {
                    HasRate = bo;
                });
			#endif
		}
	}
            
}
